rm(list = ls())

library(checkpoint)
library(texreg)

checkpoint("2018-06-15", project = "own_wd", checkpointLocation = "checkpoint_location")

type <- "four_reg.html"
resultspath <- "resultspath" # the estimates from models_appendix_d_e.R

wd <- "own_wd_path"

load(file=paste0(resultspath, 'm_1.RData'))
load(file=paste0(resultspath, 'm_2.RData'))
load(file=paste0(resultspath, 'm_3.RData'))
load(file=paste0(resultspath, 'm_4.RData'))
load(file=paste0(resultspath, 'm_5.RData'))
load(file=paste0(resultspath, 'm_6.RData'))


###########
# Table 1 #
###########

htmlreg(l=list(m.1[[1]], m.1[[2]], m.2[[1]]),
        digits=2, file=paste0(wd, "table1", type),
        caption="",
        single.row=TRUE,
        custom.gof.names = c(NA,
                             NA,
                             NA,
                             NA,
                             "Country*Years",
                             "Countries",
                             "Var Country*Years: Intercept",
                             "Var Country*Years: Extreme Left",
                             "Var Country*Years: Center",
                             "Var Country*Years: Right",
                             "Var Country*Years: Extreme Right",
                             "Cov Country*Years: Intercept, Ext Left",
                             "Cov Country*Years: Intercept, Center",
                             "Cov Country*Years: Intercept, Right",
                             "Cov Country*Years: Intercept, Ext Right",
                             "Cov Country*Years: Ext Left, Center",
                             "Cov Country*Years: Ext Left, Right",
                             "Cov Country*Years: Ext Left, Ext Right",
                             "Cov Country*Years: Center, Right",
                             "Cov Country*Years: Center, Ext Right",
                             "Cov Country*Years: Right, Ext Right",
                             "Var Country: Intercept"),
        custom.coef.map = list("(Intercept)"="Intercept",
                               rideol1="Extreme left (base: left)",
                               rideol3="Center",
                               rideol4="Right",
                               rideol5="Extreme right",
                               gov_dist="Distance from the gov.",
                               union1 = "Union member (dichot.)",
                               prtdgcl_num = "Party ID (cont.)",
                               gender1="Male",
                               agea="Age (cont.)",
                               eduyrs="Years of education (cont.)",
                               domicil2="Suburbs (base: big city)",
                               domicil3="Small City",
                               domicil4="Village",
                               domicil5="Countryside",
                               unemployed1="Unemployed",
                               gov_genlr="Gov. L-R",
                               gdp_wb_ppp="GDP (ppp, 2011 US$)",
                               wb_vae="Voice & Accountability",
                               region22="Northern Europe (base: Western)",
                               region23="Southern Europe",
                               region24="Eastern Europe",
                               year_num="Year of Survey",
                               "region22:rideol1"="Ext Left*NE",
                               "region22:rideol2"="Left*NE",
                               "region22:rideol3"="Center*NE",
                               "region22:rideol4"="Right*NE",
                               "region22:rideol5"="Ext Right*NE",
                               "region23:rideol1"="Ext Left*SE",
                               "region23:rideol2"="Left*SE",
                               "region23:rideol3"="Center*SE",
                               "region23:rideol4"="Right*SE",
                               "region23:rideol5"="Ext Right*SE",
                               "region24:rideol1"="Ext Left*EE",
                               "region24:rideol2"="Left*EE",
                               "region24:rideol3"="Center*EE",
                               "region24:rideol4"="Right*EE",
                               "region24:rideol5"="Ext Right*EE",
                               "rideol1:year_num"="Ext Left*Year",
                               "rideol3:year_num"="Center*Year",
                               "rideol4:year_num"="Right*Year",
                               "rideol5:year_num"="Ext Right*Year",
                               "region22:rideol1:year_num"="NE*Year*Ext Left",
                               "region23:rideol1:year_num"="SE*Year*Ext Left",
                               "region24:rideol1:year_num"="EE*Year*Ext Left",
                               "region22:rideol3:year_num"="NE*Year*Center",
                               "region23:rideol3:year_num"="SE*Year*Center",
                               "region24:rideol3:year_num"="EE*Year*Center",
                               "region22:rideol4:year_num"="NE*Year*Right",
                               "region23:rideol4:year_num"="SE*Year*Right",
                               "region24:rideol4:year_num"="EE*Year*Right",
                               "region22:rideol4:year_num"="NE*Year*Right",
                               "region23:rideol5:year_num"="SE*Year*Ext Right",
                               "region24:rideol5:year_num"="EE*Year*Ext Right"))


#################
#### Table 3 ####
#################

htmlreg(l=list(m.4[[1]], m.4[[2]]),
        caption = "",  
        digits=2, file=paste0(wd, "table3", type),
        single.row=TRUE,
        custom.gof.names = c(NA,
                             NA,
                             NA,
                             NA,
                             "Country*Years",
                             "Countries",
                             "Var Country*Years: Intercept",
                             "Var Country*Years: Extreme Left",
                             "Var Country*Years: Center",
                             "Var Country*Years: Right",
                             "Var Country*Years: Extreme Right",
                             "Cov Country*Years: Intercept, Ext Left",
                             "Cov Country*Years: Intercept, Center",
                             "Cov Country*Years: Intercept, Right",
                             "Cov Country*Years: Intercept, Ext Right",
                             "Cov Country*Years: Ext Left, Center",
                             "Cov Country*Years: Ext Left, Right",
                             "Cov Country*Years: Ext Left, Ext Right",
                             "Cov Country*Years: Center, Right",
                             "Cov Country*Years: Center, Ext Right",
                             "Cov Country*Years: Right, Ext Right",
                             "Var Country: Intercept"),
        custom.coef.map = list("(Intercept)"="Intercept",
                               rideol1="Extreme left (base: left)",
                               rideol3="Center",
                               rideol4="Right",
                               rideol5="Extreme right",
                               gov_dist="Distance from the gov.",
                               union1 = "Union member (dichot.)",
                               prtdgcl_num = "Party ID (cont.)",
                               gender1="Male",
                               agea="Age (cont.)",
                               eduyrs="Years of education (cont.)",
                               domicil2="Suburbs (base: big city)",
                               domicil3="Small City",
                               domicil4="Village",
                               domicil5="Countryside",
                               unemployed1="Unemployed",
                               gov_genlr="Gov. L-R",
                               gdp_wb_ppp="GDP (ppp, 2011 US$)",
                               wb_vae="Voice & Accountability",
                               region22="Northern Europe (base: Western)",
                               region23="Southern Europe",
                               region24="Eastern Europe",
                               "region22:prtdgcl_num"="NE:Party ID",
                               "region23:prtdgcl_num"="SE:Party ID",
                               "region24:prtdgcl_num"="EE:Party ID",
                               "region22:rideol1"="NE:Ext Left",
                               "region23:rideol1"="SE:Ext Left",
                               "region24:rideol1"="EE:Ext Left",
                               "region22:rideol3"="NE:Center",
                               "region23:rideol3"="SE:Center",
                               "region24:rideol3"="EE:Center",
                               "region22:rideol4"="NE:Right",
                               "region23:rideol4"="SE:Right",
                               "region24:rideol4"="EE:Right",
                               "region22:rideol5"="NE:Ext Right",
                               "region23:rideol5"="SE:Ext Right",
                               "region24:rideol5"="EE:Ext Right",
                               "rideol1:prtdgcl_num"="Ext Left:Party ID",
                               "rideol3:prtdgcl_num"="Center:Party ID",
                               "rideol4:prtdgcl_num"="Right:Party ID",
                               "rideol5:prtdgcl_num"="Ext Right:Party ID",
                               "region22:rideol1:prtdgcl_num"="NE:Ext Left:Party ID",
                               "region23:rideol1:prtdgcl_num"="SE:Ext Left:Party ID",
                               "region24:rideol1:prtdgcl_num"="EE:Ext Left:Party ID",
                               "region22:rideol3:prtdgcl_num"="NE:Center:Party ID",
                               "region23:rideol3:prtdgcl_num"="SE:Center:Party ID",
                               "region24:rideol3:prtdgcl_num"="EE:Center:Party ID",
                               "region22:rideol4:prtdgcl_num"="NE:Right:Party ID",
                               "region23:rideol4:prtdgcl_num"="SE:Right:Party ID",
                               "region24:rideol4:prtdgcl_num"="EE:Right:Party ID",
                               "region22:rideol5:prtdgcl_num"="NE:Ext Right:Party ID",
                               "region23:rideol5:prtdgcl_num"="SE:Ext Right:Party ID",
                               "region24:rideol5:prtdgcl_num"="EE:Ext Right:Party ID"))


#################
#### Table 4 ####
#################

htmlreg(l=list(m.5[[1]], m.5[[2]], m.6[[1]]),
        caption = "",  
        digits=2, file=paste0(wd, "table4", type),
        single.row=TRUE,
        custom.gof.names = c(NA,
                             NA,
                             NA,
                             NA,
                             "Country*Years",
                             "Countries",
                             "Var Country*Years: Intercept",
                             "Var Country*Years: Extreme Left",
                             "Var Country*Years: Center",
                             "Var Country*Years: Right",
                             "Var Country*Years: Extreme Right",
                             "Cov Country*Years: Intercept, Ext Left",
                             "Cov Country*Years: Intercept, Center",
                             "Cov Country*Years: Intercept, Right",
                             "Cov Country*Years: Intercept, Ext Right",
                             "Cov Country*Years: Ext Left, Center",
                             "Cov Country*Years: Ext Left, Right",
                             "Cov Country*Years: Ext Left, Ext Right",
                             "Cov Country*Years: Center, Right",
                             "Cov Country*Years: Center, Ext Right",
                             "Cov Country*Years: Right, Ext Right",
                             "Var Country: Intercept"),
        custom.coef.map = list("(Intercept)"="Intercept",
                               rideol1="Extreme left (base: left)",
                               rideol3="Center",
                               rideol4="Right",
                               rideol5="Extreme right",
                               gov_dist="Distance from the gov.",
                               union1 = "Union member (dichot.)",
                               prtdgcl_num = "Party ID (cont.)",
                               gender1="Male",
                               agea="Age (cont.)",
                               eduyrs="Years of education (cont.)",
                               domicil2="Suburbs (base: big city)",
                               domicil3="Small City",
                               domicil4="Village",
                               domicil5="Countryside",
                               unemployed1="Unemployed",
                               gov_genlr="Gov. L-R",
                               gdp_wb_ppp="GDP (ppp, 2011 US$)",
                               wb_vae="Voice & Accountability",
                               region22="Northern Europe (base: Western)",
                               region23="Southern Europe",
                               region24="Eastern Europe",
                               "region22:gov_dist"="Gov. dist*NE",
                               "region23:gov_dist"="Gov. dist*SE",
                               "region24:gov_dist"="Gov. dist*EE",
                               "region22:gov_genlr"="Gov. L-R*NE",
                               "region23:gov_genlr"="Gov. L-R*SE",
                               "region24:gov_genlr"="Gov. L-R*EE",
                               "gov_genlr:gov_dist"="Gov. L-R*Gov. dist",
                               "region22:gov_genlr:gov_dist"="Gov. L-R*NE*Gov. dist",
                               "region23:gov_genlr:gov_dist"="Gov. L-R*SE*Gov. dist",
                               "region24:gov_genlr:gov_dist"="Gov. L-R*EE*Gov. dist"))
